import Vue from 'vue'
import Router from 'vue-router'
import axios from 'axios'

Vue.use(Router)

const router = new Router({
  routes: [
    //首页-路由
    //{
    //   path: '/',
    //   name: 'Home',
    //   meta: {
    //     keepAlive: true,
    //     serviceOnlineShow: true
    //   },
    //   component: () => import('@/pages/Home/Home')
    // },
    {
      //404
      path: '/',
      name: 'error',
      component: () => import('@/pages/error/error')
    },
    {
      //成为店主-路由
      path: '/experience',
      name: 'Experience',
      meta: {
        keepAlive: true
      },
      component: () => import('@/pages/Experience/Experience')
    },
    {
      //成为普通会员-路由
      path: '/experience2',
      name: 'Experience2',
      meta: {
        keepAlive: true
      },
      component: () => import('@/pages/Experience/Experience2')
    },
    {
      //商品分类-路由
      path: '/goodsList',
      name: 'GoodsList',
      component: () => import('@/pages/GoodsList/GoodsListNew')
    },
    {
      //消息中心-路由
      path: '/messageCenter',
      name: 'MessageCenter',
      component: () => import('@/pages/MessageCenter/MessageCenter')
    },
    {
      //消息中心-消息列表-路由
      path: '/messageCenter/messageDetail',
      name: 'MessageDetail',
      component: () => import('@/pages/MessageCenter/MessageDetail')
    },
    {
      //商品详情-路由
      path: '/goodsDetail',
      name: 'GoodsDetail',
      component: () => import('@/pages/GoodsDetail/GoodsDetail')
    },
    {
      //商品评论-路由
      path: '/goodsEvaluate',
      name: 'GoodsEvaluate',
      component: () => import('@/pages/GoodsDetail/GoodsEvaluate')
    },
    {
      //购物车-路由
      path: '/cart',
      name: 'Cart',
      component: () => import('@/pages/Cart/Cart')
    },
    {
      //个人中心-路由
      path: '/userCenter',
      name: 'UserCenter',
      component: () => import('@/pages/UserCenter/UserCenter')
    },
    {
      //个人中心-个人信息-路由
      path: '/userInfo',
      name: 'UserInfo',
      component: () => import('@/pages/UserCenter/UserInfo')
    },
    {
      //个人中心-店主-路由
      path: '/shopKeeper',
      name: 'ShopKeeper',
      component: () => import('@/pages/UserCenter/ShopKeeper')
    },
    {
      //个人中心-服务商-路由
      path: '/serviceProvider',
      name: 'ServiceProvider',
      component: () => import('@/pages/UserCenter/ServiceProvider')
    },
    {
      //个人中心-个人账户-路由
      path: '/userCenter/userAccount',
      name: 'UserAccount',
      component: () => import('@/pages/UserCenter/UserAccount')
    },
    {
      //个人中心-个人账户-提现-路由
      path: '/userCenter/withdrawCash',
      name: 'WithdrawCash',
      component: () => import('@/pages/UserCenter/WithdrawCash')
    },
    {
      //个人中心-个人账户-提现选择-路由
      path: '/userCenter/withdraw',
      name: 'Withdraw',
      component: () => import('@/pages/UserCenter/Withdraw')
    },
    {
      //个人中心-个人账户-提现-提现记录列表-路由
      path: '/userCenter/withdrawRecord',
      name: 'WithdrawRecord',
      component: () => import('@/pages/UserCenter/WithdrawRecord')
    },
    {
      //个人中心-个人账户-提现-提现记录详情-路由
      path: '/userCenter/withdrawDetail',
      name: 'WithdrawDetail',
      component: () => import('@/pages/UserCenter/WithdrawDetail')
    },
    {
      //个人中心-申请退押金-路由
      path: '/userCenter/refundDeposit',
      name: 'RefundDeposit',
      component: () => import('@/pages/UserCenter/RefundDeposit')
    },
    {
      //个人中心-个人账户-明细-路由
      path: '/userCenter/userAccountDetail',
      name: 'UserAccountDetail',
      component: () => import('@/pages/UserCenter/UserAccountDetail')
    },
    {
      //个人中心-个人账户-累计收益明细-路由
      path: '/userCenter/incomeDetail',
      name: 'IncomeDetail',
      component: () => import('@/pages/UserCenter/IncomeDetail')
    },
    {
      //个人中心-个人账户-累计收益明细-路由
      path: '/userCenter/watingAccount',
      name: 'WatingAccount',
      component: () => import('@/pages/UserCenter/WatingAccount')
    },
    {
      //个人中心-个人信息-姓名编辑-路由
      path: '/userInfo/userName',
      name: 'UserName',
      component: () => import('@/pages/UserCenter/UserName')
    },
    {
      //个人中心-个人信息-性别选择-路由
      path: '/userInfo/userSex',
      name: 'UserSex',
      component: () => import('@/pages/UserCenter/UserSex')
    },
    {
      //个人中心-个人信息-生日选择-路由
      path: '/userInfo/userBirthday',
      name: 'UserBirthday',
      component: () => import('@/pages/UserCenter/UserBirthday')
    },
    {
      //个人中心-代理商信息-路由
      path: '/agentInfo',
      name: 'AgentInfo',
      component: () => import('@/pages/UserCenter/AgentInfo')
    },
    {
      //个人中心-代理商授权次数-路由
      path: '/agentTimes',
      name: 'AgentTimes',
      component: () => import('@/pages/UserCenter/AgentTimes')
    },
    {
      //个人中心-代理商授权列表-路由
      path: '/attorneyList',
      name: 'AttorneyList',
      component: () => import('@/pages/UserCenter/AttorneyList')
    },
    {
      //个人中心-个人信息-我的二维码-路由
      path: '/userInfo/myCode',
      name: 'MyCode',
      meta: {
        keepAlive: true
      },
      component: () => import('@/pages/UserCenter/MyCode')
    },
    {
      //普通商品确认订单-路由
      path: '/orderConfirm',
      name: 'OrderConfirm',
      component: () => import('@/pages/OrderConfirm/OrderConfirm')
    },
    {
      //vip商品确认订单-路由
      path: '/vipConfirm',
      name: 'VipConfirm',
      component: () => import('@/pages/OrderConfirm/VipConfirm')
    },
    {
      //支付方式-路由
      path: '/goPay',
      name: 'GoPay',
      component: () => import('@/pages/GoPay/GoPay')
    },
    {
      //订单列表-路由
      path: '/orderList',
      name: 'OrderList',
      component: () => import('@/pages/Order/orderList')
    },
    {
      //退换货订单-路由
      path: '/refundOrder',
      name: 'RefundOrder',
      component: () => import('@/pages/Order/RefundOrder')
    },
    {
      //订单详情-路由
      path: '/orderDetail',
      name: 'OrderDetail',
      component: () => import('@/pages/Order/OrderDetail')
    },
    {
      //收货地址-路由
      path: '/address',
      name: 'Address',
      component: () => import('@/pages/Address/Address')
    },
    {
      //添加收货地址-路由
      path: '/address/add',
      name: 'AddAddress',
      component: () => import('@/pages/Address/AddAddress')
    },
    {
      //编辑收货地址-路由
      path: '/address/edit',
      name: 'EditAddress',
      component: () => import('@/pages/Address/EditAddress')
    },
    {
      //帮助中心-路由
      path: '/helpCenter',
      name: 'HelpCenter',
      meta: {
        keepAlive: true
      },
      component: () => import('@/pages/HelpCenter/HelpCenter')
    },
    {
      //帮助中心-列表-路由
      path: '/helpCenter/list',
      name: 'HelpList',
      component: () => import('@/pages/HelpCenter/HelpList')
    },
    {
      //帮助中心-详情-路由
      path: '/helpCenter/detail',
      name: 'HelpDetail',
      component: () => import('@/pages/HelpCenter/HelpDetail')
    },
    {
      //在线客服-路由
      path: '/serviceOnline',
      name: 'ServiceOnline',
      component: () => import('@/pages/ServiceOnline/ServiceOnline')
    },
    {
      //订单物流-路由
      path: '/logistics',
      name: 'Logistics',
      component: () => import('@/pages/Logistics/Logistics')
    },
    {
      //数据管理-路由
      path: '/team',
      name: 'Team',
      component: () => import('@/pages/Team/Team')
    },
    {
      //数据管理-详情-路由
      path: '/teamList',
      name: 'TeamList',
      component: () => import('@/pages/Team/TeamList')
    },
    {
      //发表评论-路由
      path: '/comment',
      name: 'Comment',
      component: () => import('@/pages/Comment/Comment')
    },
    {
      //发表评论-列表-路由
      path: '/commentList',
      name: 'CommentList',
      component: () => import('@/pages/Comment/CommentList')
    },
    {
      //退换货-路由
      path: '/refund',
      name: 'Refund',
      component: () => import('@/pages/Refund/Refund')
    },
    {
      //取消订单-路由
      path: '/orderCancle',
      name: 'OrderCancle',
      component: () => import('@/pages/OrderCancle/OrderCancle')
    },
    {
      //确认收货-路由
      path: '/receiveConfirm',
      name: 'ReceiveConfirm',
      component: () => import('@/pages/ReceiveConfirm/ReceiveConfirm')
    },
    {
      //加入我们-类型选择-路由
      path: '/joinUs/typeSelect',
      name: 'TypeSelect',
      component: () => import('@/pages/JoinUs/TypeSelect')
    },
    {
      //加入我们-规则-路由
      path: '/joinUs/rules',
      name: 'Rules',
      component: () => import('@/pages/JoinUs/Rules')
    },
    {
      //加入我们-流程-路由
      path: '/joinUs/joinStep',
      name: 'JoinStep',
      component: () => import('@/pages/JoinUs/JoinStep')
    },
    {
      //加入我们-信息填写-路由
      path: '/joinUs/infoInput',
      name: 'InfoInput',
      component: () => import('@/pages/JoinUs/InfoInput')
    },
    {
      //关于我们-路由
      path: '/about',
      name: 'About',
      meta: {
        keepAlive: true
      },
      component: () => import('@/pages/About/About')
    },
    {
      //静态页-路由
      path: '/index3',
      name: 'Index3',
      meta: {
        keepAlive: true
      },
      component: () => import('@/pages/StaticPages/Index3')
    },
    {
      //我的银行卡-路由
      path: '/myCard',
      name: 'MyCard',
      component: () => import('@/pages/Card/MyCard')
    },
    {
      //添加银行卡-路由
      path: '/addCard',
      name: 'AddCard',
      component: () => import('@/pages/Card/AddCard')
    },
    {
      //银行卡选择-路由
      path: '/cardSelect',
      name: 'CardSelect',
      component: () => import('@/pages/Card/CardSelect')
    },
    {
      //素材管理-路由
      path: '/imgManager',
      name: 'ImgManager',
      meta: {
        keepAlive: true
      },
      component: () => import('@/pages/SourceManager/ImgManager')
    },
    {
      //素材管理-路由
      path: '/wordManager',
      name: 'WordManager',
      meta: {
        keepAlive: true
      },
      component: () => import('@/pages/SourceManager/WordManager')
    },
    {
      //素材管理-海报素材-路由
      path: '/imgSource',
      name: 'ImgSource',
      component: () => import('@/pages/SourceManager/ImgSource')
    },
    {
      //素材管理-文案素材-路由
      path: '/wordSource',
      name: 'WordSource',
      component: () => import('@/pages/SourceManager/WordSource')
    },
    {
      //拼团-路由
      path: '/groupBuy',
      name: 'GroupBuy',
      meta: {
        keepAlive: true
      },
      component: () => import('@/pages/GroupBuy/GroupBuy')
    },
    {
      //拼团静态页1-路由
      path: '/groupBuyIndex1',
      name: 'GroupBuyIndex1',
      meta: {
        keepAlive: true
      },
      component: () => import('@/pages/GroupBuy/GroupBuyIndex1')
    },
    {
      //拼团静态页2-路由
      path: '/groupBuyIndex2',
      name: 'GroupBuyIndex2',
      meta: {
        keepAlive: true
      },
      component: () => import('@/pages/GroupBuy/GroupBuyIndex2')
    },
    {
      //拼团-详情-路由
      path: '/groupDetail',
      name: 'GroupDetail',
      component: () => import('@/pages/GroupBuy/GroupDetail')
    },
    {
      //拼团-参与拼团-路由
      path: '/joinGroup',
      name: 'JoinGroup',
      component: () => import('@/pages/GroupBuy/JoinGroup')
    },
    {
      //拼团-参与拼团-路由
      path: '/myGroup',
      name: 'MyGroup',
      component: () => import('@/pages/GroupBuy/MyGroup')
    },
    {
      //拼团-规则-路由
      path: '/groupRules',
      name: 'GroupRules',
      meta: {
        keepAlive: true
      },
      component: () => import('@/pages/GroupBuy/GroupRules')
    },
    {
      //专题活动页-路由
      path: '/activity_1',
      name: 'Activity_1',
      component: () => import('@/pages/Activity/Index_1')
    },
    {
      //百领社区-路由
      path: '/socialSystem',
      name: 'SocialSystem',
      component: () => import('@/pages/SocialSystem/SocialSystem')
    },
    {
      //百领社区-文章-路由
      path: '/socialSystem/artical',
      name: 'Artical',
      component: () => import('@/pages/SocialSystem/Artical')
    },
    {
      //百领社区-文章-路由
      path: '/socialSystem/writeArtical',
      name: 'WriteArtical',
      component: () => import('@/pages/SocialSystem/WriteArtical')
    },
    {
      //百领社区-我的文章-路由
      path: '/socialSystem/myArtical',
      name: 'MyArtical',
      component: () => import('@/pages/SocialSystem/MyArtical')
    },
    {
      //填写邀请码-路由
      path: '/inviteCode',
      name: 'InviteCode',
      component: () => import('@/pages/InviteCode/InviteCode')
    },
    {
      //搜索-路由
      path: '/search',
      name: 'SearchPage',
      component: () => import('@/pages/Search/SearchPage')
    },
    {
      //搜索-路由
      path: '/searchResult',
      name: 'SearchResult',
      component: () => import('@/pages/Search/SearchResult')
    },
    {
      //明星店主-路由
      path: '/star',
      name: 'StarIndex',
      component: () => import('@/pages/Star/StarIndex')
    },
    {
      //明星店主-路由
      path: '/starDetail',
      name: 'StarDetail',
      component: () => import('@/pages/Star/StarDetail')
    },
    {
      //设置登录信息-路由
      path: '/test',
      name: 'Test',
      component: () => import('@/pages/Test/Test')
    }
  ],
  scrollBehavior(to, from, savedPosition) {
    return {
      x: 0,
      y: 0
    }
  }
})

router.beforeEach((to, from, next) => {
  if (to.path == '/') {
    next()
  } else {
    next({
      path: '/'
    })
  }
  // if (to.path == '/test') {
  //   next()
  // }
  // let userInfo = sessionStorage.getItem('userInfo')
  // if (userInfo === null || userInfo === '') {
  //   axios.post('/api/user/my_info.json').then(res => {
  //     const data = res.data
  //     if (data.status == 1) {
  //       sessionStorage.setItem('userInfo', JSON.stringify(data.data))
  //       next()
  //     }
  //   })
  // } else {
  //   next()
  // }
})

export default router
